home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / Hardware / BlizKick / Modules / SCSIDEV43.ASM < prev    next >
Assembly Source File  |  1999-11-06  |  6KB  |  299 lines

  1. ; FILE: Source:modules/SCSIDEV43.ASM          REV: 5 --- Install V43 scsi.device
  2.  
  3. ;
  4. ; Plant V43 scsi.device -Module
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This patch module will install V43 scsi.device replacing one inside
  7. ; kickstart. It will also disable beta message of the scsi.device :)
  8. ;
  9. ; Device will be loaded from file "devs:scsi43.device".
  10. ;
  11. ; This module has been tested with following scsi.device (a300.ld.strip)
  12. ;  versions:
  13. ;
  14. ;    43.11 (3.9.96)    Works fine for me.
  15. ;    43.17 (12.5.97)    Works, but doesn't recognize my drives! :(
  16. ;    43.18 (15.6.97)    Works fine.
  17. ;    43.23 (7.11.97)    Works fine.
  18. ;    43.24 (9.11.98)    Works fine.
  19. ;
  20. ; Written by Harry Sintonen.
  21. ; This source code is Public Domain.
  22. ;
  23.  
  24.     incdir    "include:"        ; Some required...
  25.     include    "exec/types.i"
  26.     include    "exec/libraries.i"
  27.     include    "blizkickmodule.i"
  28.  
  29. SCSI_MAXSIZE    EQU    16384+4096
  30.  
  31. _LVOCopyMem    EQU    -$270
  32.  
  33. _LVOIoErr    EQU    -$84
  34. _LVOLoadSeg    EQU    -$96
  35. _LVOUnLoadSeg    EQU    -$9C
  36. _LVOSetIoErr    EQU    -$1CE
  37.  
  38. call    MACRO
  39.     jsr    (_LVO\1,a6)
  40.     ENDM
  41.  
  42.     SECTION    PATCH,CODE
  43. _DUMMY_LABEL
  44.     BK_PTC
  45.  
  46. ; Code is run with following incoming parameters:
  47. ;
  48. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  49. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  50. ; d0=ROM lenght in bytes    eg. $00080000
  51. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  52. ;    CALL: jsr (a2)
  53. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  54. ;     OUT: d0=ptr to resident (buf) or NULL
  55. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  56. ;    CALL: jsr (a3)
  57. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  58. ;     OUT: d0=success
  59. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  60. ;    CALL: jsr (a4)
  61. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  62. ;     OUT: -
  63. ; d6=dosbase, a6=execbase
  64. ;
  65. ; Code should return:
  66. ;
  67. ; d0=true if succeeded, false if failed.
  68. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  69.  
  70.  
  71. ; NOTE: Kickstart *is* 2.0+
  72.  
  73.     cmp.w    #39,($C,a0)        ; Requires KS ROM V3.1+
  74.     bhs.b    .go
  75.     moveq    #0,d0
  76.     rts
  77.  
  78. .go    movem.l    d0/a0-a1,-(sp)
  79.     moveq    #0,d7
  80.  
  81.     lea    (_scsiname,pc),a1    ; _FindResident
  82.     jsr    (a2)
  83.     tst.l    d0
  84.     beq    .xit
  85.     move.l    d0,a5            ; a5=scsi.device resident
  86.  
  87.     moveq    #1,d7
  88.     move.l    (RT_IDSTRING,a5),a0
  89.     sub.l    (2*4,sp),a0        ;[a1]
  90.     add.l    (1*4,sp),a0        ;[a0]
  91.     lea    (_hdiname,pc),a1
  92.     moveq    #12-1,d1        ; 'IDE_scsidisk'
  93. .cmp    move.b    (a0)+,d0
  94.     cmp.b    (a1)+,d0
  95.     dbne    d1,.cmp
  96.     tst.w    d1            ; Test if already installed
  97.     bmi    .xit
  98.  
  99.     moveq    #0,d7
  100.     moveq    #-1,d4            ; IoErr=-1 (default)
  101.     exg    d6,a6
  102.     lea    (_hddname,pc),a0
  103.     move.l    a0,d1
  104.     call    LoadSeg
  105.     move.l    d0,d5
  106.     beq    .exit
  107.  
  108.     move.l    d5,a2
  109.     add.l    a2,a2
  110.     add.l    a2,a2
  111.     tst.l    (a2)+            ; Requires single hunk exe!
  112.     bne    .baddie            ; a2=hunk start
  113.  
  114.     moveq    #127,d0            ; Find resident:
  115.     move.w    #$4AFC,d1
  116.     move.l    a2,a0
  117. .findrt    cmp.w    (a0)+,d1
  118.     dbeq    d0,.findrt
  119.     tst.w    d0
  120.     bmi    .baddie
  121.     subq.l    #2,a0
  122.     cmp.l    (RT_MATCHTAG,a0),a0
  123.     bne.b    .findrt
  124.  
  125.     tst.b    (RT_FLAGS,a0)        ; Allow no RTF_AUTOINIT
  126.     bmi    .baddie
  127.  
  128.     ; a0=residenttag (loadsed), a2=1st seg start
  129.     bsr    makepcrel
  130.  
  131.     ; a0=residenttag (loadsed), a2=1st seg start
  132.     bsr    disablebeta
  133.  
  134.     lea    (_buf,pc),a1
  135.     move.l    #BKMODULE_ID,(a1)+    ; bkm_ID
  136.     move.l    #(0)<<16!RTC_MATCHWORD,(a1)+ ; bkm_Flags RT_MATCHWORD
  137.     clr.l    (a1)+            ; RT_MATCHTAG
  138.     moveq    #RT_SIZE,d0
  139.     add.l    (RT_ENDSKIP,a0),d0
  140.     sub.l    a2,d0
  141.     cmp.l    #SCSI_MAXSIZE,d0    ; Too big?
  142.     bhi.b    .baddie            ; It is quit!
  143.  
  144.     move.l    d0,(a1)+        ; RT_ENDSKIP
  145.     move.l    (RT_FLAGS,a0),(a1)+    ; RT_FLAGS,RT_VERSION,RT_TYPE,RT_PRI
  146.     moveq    #RT_SIZE,d0
  147.     add.l    (RT_NAME,a0),d0
  148.     sub.l    a2,d0
  149.     move.l    d0,(a1)+        ; RT_NAME
  150.     moveq    #RT_SIZE,d0
  151.     add.l    (RT_IDSTRING,a0),d0
  152.     sub.l    a2,d0
  153.     move.l    d0,(a1)+        ; RT_IDSTRING
  154.     moveq    #RT_SIZE,d0
  155.     add.l    (RT_INIT,a0),d0
  156.     sub.l    a2,d0
  157.     move.l    d0,(a1)+        ; RT_INIT
  158.  
  159.     clr.w    (a0)            ; Kill old RT_MATCHWORD
  160.  
  161.     movem.l    a0-a1,-(sp)
  162.     move.l    (RT_ENDSKIP,a0),d0
  163.     sub.l    a2,d0
  164.     move.l    a2,a0
  165.     exg    d6,a6            ;ex6--
  166.     call    CopyMem
  167.     movem.l    (sp)+,a0-a1
  168.  
  169. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  170.     movem.l    (sp),d0/a0        ;[d0][a0]
  171.     lea    (_buf,pc),a1
  172.  
  173.     move.w    ($C,a0),d1        ; Kludge fix kick version to scsi version...
  174.     move.b    (bkm_ResTag+RT_VERSION,a1),($C+1,a0)
  175.     jsr    (a3)            ; _InstallModule
  176.     move.w    d1,($C,a0)        ; Restore kick version
  177.     exg    d6,a6            ;--ex6
  178.     move.l    d0,d7            ; set success flag
  179.  
  180.     call    IoErr
  181.     move.l    d0,d4
  182.  
  183.     lea    (_nullstr,pc),a2
  184.     tst.l    d7
  185.     beq.b    .bskip2
  186.  
  187.     clr.w    (a5)            ; Kill ROM scsi.device ROMTag :)
  188.  
  189. .baddie    lea    (_error2,pc),a2
  190. .bskip2    move.l    d5,d1
  191.     call    UnLoadSeg
  192.     bra.b    .bskip
  193.  
  194. .exit    lea    (_error1,pc),a2        ; a0=fmt
  195. .bskip
  196.     exg    d6,a6
  197.     move.l    d7,d0            ; Valid counter?
  198.     bne.b    .xit
  199.     move.l    a2,a0            ; a0=fmt
  200.     pea    (_hddname,pc)
  201.     move.l    sp,a1            ; a1=array
  202.     jsr    (a4)            ; Call _Printf
  203.     addq.l    #4,sp
  204.  
  205.     move.l    d4,d1
  206.     addq.l    #1,d4
  207.     beq.b    .skip
  208.     exg    d6,a6
  209.     call    SetIoErr
  210. .skip
  211.     moveq    #0,d0            ; Return fail
  212. .xit    lea    (3*4,sp),sp
  213.     rts
  214.  
  215.  
  216.  
  217. ; a0=residenttag (loadsed), a2=1st seg start
  218. makepcrel    move.l    a0,-(sp)
  219.     move.l    (RT_ENDSKIP,a0),d3    ;d3=max
  220.     move.l    a2,d2            ;d2=min
  221.     move.l    a2,a0
  222.  
  223. .mpcloop    addq.l    #2,a0
  224.     cmp.l    a0,d3
  225.     bls.b    .mpcldone
  226.  
  227.     move.l    (a0),d0
  228.     cmp.l    d0,d2
  229.     bhi.b    .mpcloop
  230.     cmp.l    d0,d3
  231.     bls.b    .mpcloop
  232.  
  233.     move.l    (-2,a0),d1
  234.  
  235.     cmp.l    #$4EB90000,d1        ; jsr abs.l -> jsr asb(pc); nop
  236.     bne.b    .mpcs0
  237.     sub.l    a0,d0
  238.     move.w    #$4EBA,(-2,a0)
  239.     move.w    d0,(a0)+
  240.     move.w    #$4E71,(a0)
  241.     ;bra.b    .mpcloop
  242. .mpcs0
  243.     bra.b    .mpcloop
  244. .mpcldone
  245.     move.l    (sp)+,a0
  246.     rts
  247.  
  248.  
  249. ; a0=residenttag (loadsed), a2=1st seg start
  250. disablebeta    move.l    a0,-(sp)
  251.     moveq    #-(5*4),d3
  252.     add.l    (RT_ENDSKIP,a0),d3    ;d3=max
  253.     move.l    (RT_INIT,a0),d2        ;d2=min
  254.     move.l    d2,a0
  255.  
  256.     move.l    #$48E7C0C0,d1        ;preload
  257.  
  258. .loop    addq.l    #2,a0
  259.     cmp.l    a0,d3
  260.     bls.b    .done
  261.  
  262.     cmp.l    (a0),d1
  263.     bne.b    .loop
  264.     cmp.w    #$206D,(4,a0)
  265.     bne.b    .loop
  266.     tst.b    (6,a0)
  267.     bne.b    .loop
  268.     move.l    (8,a0),d0
  269.     and.l    #$FFFFFFF0,d0
  270.     cmp.l    #$224E7000,d0
  271.     bne.b    .loop
  272.     cmp.w    #$6100,(12,a0)
  273.     bne.b    .loop
  274.     cmp.l    #$4CDF0303,(16,a0)
  275.     bne.b    .loop
  276.  
  277.     move.w    #$6012,(a0)        ;skip it!
  278. .done
  279.     move.l    (sp)+,a0
  280.     rts
  281.  
  282.  
  283. _scsiname    dc.b    'scsi.device',0
  284. _hdiname    dc.b    'IDE_scsidisk',0
  285. _hddname    dc.b    'devs:scsi43.device',0
  286.  
  287. _error1    dc.b    'Couldn''t load "%s"!',10,0
  288. _error2    dc.b    'Couldn''t utilize this %s version!',10,0
  289. _nullstr    EQU    *-1
  290.  
  291.  
  292.     CNOP    0,4
  293. _buf    ds.b    SCSI_MAXSIZE+bkm_ResTag+RT_SIZE
  294.  
  295.  
  296.     SECTION    VERSION,DATA
  297.  
  298.     dc.b    '$VER: SCSIDEV43_PATCH 1.2 (12.11.98)',0
  299.